<script type="text/javascript" src="<?php echo Yii::app()->baseUrl ?>/scripts/jquery/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        module = '<?php echo $pagevals['module'];?>';
        $("#module").val(module);
        system_account = '<?php echo $pagevals['system_account'];?>';
        $("#system_account").val(system_account);
        
       $("#system_account").change(function(){
            var filter_system_account = $("#system_account").val();
            action = "?r=systemAccountPermision/index&system_account="+filter_system_account+"&module="+module;
            window.location = action;
       });
       $("#module").change(function(){
           var filter_module = $("#module").val();
            action = "?r=systemAccountPermision/index&system_account="+system_account+"&module="+filter_module;
            window.location = action;
       });
       
       
       $('#check_all').click(function () {
            alert('dsds');
            checked = ($(this).attr('checked') == 'checked') ? 'true' : false;
            $('#permision_checkbox').each(function(){ $(this).attr('checked', checked); });
        });
    });
    
    function toggleChecked(status) {
        if(status == true){
            $(".permision").each( function() {
                //alert($(this).attr('checked'));
                this.checked =status ;
                //$(this).attr("checked","checked");

            });
        }else{
            $(".permision").each( function() {
                //alert($(this).attr('checked'));
                this.checked =status ;
                //$(this).attr("checked",false);

            });
        }
    }
</script>

<script type="text/javascript">
    

</script>


<div class="box" style="width: 100%">

    <div class="title">

        <h4>
            <span class="icon16 brocco-icon-grid"></span>
            <span>Chọn tài khoản, module và quyền tương ứng</span>
        </h4>

    </div>
    <div class="content">

        <form action="?r=systemAccountPermision/index" method="POST" class="form-horizontal">

            <div class="form-row row-fluid">
                <div class="span12">
                    <div class="row-fluid">
                        <table>
                            <tr>
                                <td><label>Tài khoản quản trị</label></td>
                                <td><label>Module</label></td>
                            </tr>
                            <tr>
                                <td>
                                    <select name="system_account" id="system_account">
                                        <?php
                                            foreach($pagevals['selection_label']['system_account'] as $value){
                                                echo '<option class="filter_label" value="'.$value.'">'.$value.'</option>';
                                            }
                                        ?>
                                    </select>
                                </td>
                                <td>
                                    <select name="module" id="module">
                                        <?php
                                            foreach($pagevals['selection_label']['module'] as $key=> $value){
                                                echo '<option class="filter_label" value="'.$key.'">'.$value.'</option>';
                                            }
                                        ?>
                                    </select>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
            
            <div class="form-row row-fluid">
                <div class="span12">
                    <div class="row-fluid" id="permision_checkbox">
                        <br />
                        <label>Quyền hạn</label>
                        <!--input style="display:none" type="checkbox" onclick="toggleChecked(this.checked)"> Select / Deselect All-->
                        <?php
                            
                        
                            $index = '<div class="left marginT5 marginR10">
                                        <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision"   name="index" value="index" id="inlineCheckbox1" style="opacity: 0;"></span></div> View all
                                    </div>';
                            $view = '<div class="left marginT5 marginR10">
                                        <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision"   name="view" value="view" id="inlineCheckbox1" style="opacity: 0;"></span></div> View
                                    </div>';
                            $edit = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox" class="permision"    name="edit" value="edit" id="inlineCheckbox1" style="opacity: 0;"></span></div> Edit
                                        </div>';
                            $create = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision"   name="create" value="create" id="inlineCheckbox1" style="opacity: 0;"></span></div> Create
                                        </div>';
                            $pending = ' <div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision"   name="pending" value="pending" id="inlineCheckbox1" style="opacity: 0;"></span></div> Pending
                                        </div>';
                            $approve = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision"   name="approve" value="approve" id="inlineCheckbox1" style="opacity: 0;"></span></div> Approve
                                        </div>';
                            $active = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision"   name="active" value="active" id="inlineCheckbox1" style="opacity: 0;"></span></div> Active
                                        </div>';
                            $block = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox" class="permision"    name="block" value="block" id="inlineCheckbox1" style="opacity: 0;"></span></div> Block
                                        </div>';
                            $remove = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision"   name="remove" value="remove" id="inlineCheckbox1" style="opacity: 0;"></span></div> Remove
                                        </div>';
                            $banned = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision"   name="banned" value="banned" id="inlineCheckbox1" style="opacity: 0;"></span></div> Banned
                                        </div>';
                            $waiting = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision"   name="waiting" value="waiting" id="inlineCheckbox1" style="opacity: 0;"></span></div> Waiting
                                        </div>';
                            $lock = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision"   name="lock" value="lock" id="inlineCheckbox1" style="opacity: 0;"></span></div> Lock
                                        </div>';
                            $sendmail = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision"   name="sendmail" value="sendmail" id="inlineCheckbox1" style="opacity: 0;"></span></div> Send Mail
                                        </div>';
                            $restore = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision"    name="restore" value="restore" id="inlineCheckbox1" style="opacity: 0;"></span></div> Restore
                                        </div>';
                            if( $pagevals['module']== 'storeconfig'){
                                $index = '<div class="left marginT5 marginR10">
                                                <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision" name="index" value="index,popup,bankinfo" id="inlineCheckbox1" style="opacity: 0;"></span></div> Setting
                                            </div>';
                                if(in_array('index', $pagevals['permision'])){
                                    $index = '<div class="left marginT5 marginR10">
                                                <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision" checked="checked" name="index" value="index,popup,bankinfo" id="inlineCheckbox1" style="opacity: 0;"></span></div> Setting
                                            </div>';
                                }
                                $permisions = $index;
                                echo $permisions;
                            }
                         
                            
                            elseif($pagevals['module']== 'useremail'){
                                if(in_array('remove', $pagevals['permision'])){
                                    $remove = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision" checked="checked" name="remove" value="remove" id="inlineCheckbox1" style="opacity: 0;"></span></div> Remove
                                        </div>';
                                }
                                if(in_array('index', $pagevals['permision'])){
                                    $index = '<div class="left marginT5 marginR10">
                                                <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision" checked="checked" name="index" value="index" id="inlineCheckbox1" style="opacity: 0;"></span></div> View all
                                            </div>';
                                }
                                if(in_array('sendmail', $pagevals['permision'])){
                                   $sendmail = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision"  checked="checked"   name="sendmail" value="sendmail" id="inlineCheckbox1" style="opacity: 0;"></span></div> Send Mail
                                        </div>';
                                }
                                $permisions= $index.$sendmail.$remove;
                                echo $permisions;
                            }
                            
                            elseif($pagevals['module']== 'systemaccountpermision'){
                                if(in_array('index', $pagevals['permision'])){
                                    $index = '<div class="left marginT5 marginR10">
                                                <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision" checked="checked" name="index" value="index" id="inlineCheckbox1" style="opacity: 0;"></span></div> Authorization
                                            </div>';
                                }
                                $permisions = $index;
                                echo $permisions;
                            }
                            
                            elseif($pagevals['module']== 'site'){
                                if(in_array('index', $pagevals['permision'])){
                                    $index = '<div class="left marginT5 marginR10">
                                                <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision" checked="checked" name="index" value="index" id="inlineCheckbox1" style="opacity: 0;"></span></div> View all
                                            </div>';
                                }
                                $permisions = $index;
                                echo $permisions;
                            }
                            
                            elseif($pagevals['module']== 'systemaccount'){
                                if(in_array('index', $pagevals['permision'])){
                                    $index = '<div class="left marginT5 marginR10">
                                                <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision" checked="checked" name="index" value="index" id="inlineCheckbox1" style="opacity: 0;"></span></div> View all
                                            </div>';
                                }
                                if(in_array('view', $pagevals['permision'])){
                                    $view = '<div class="left marginT5 marginR10">
                                        <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox" class="permision"  checked="checked" name="view" value="view" id="inlineCheckbox1" style="opacity: 0;"></span></div> View
                                    </div>';
                                }
                                if(in_array('edit', $pagevals['permision'])){
                                     $edit = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision" checked="checked" name="edit" value="edit" id="inlineCheckbox1" style="opacity: 0;"></span></div> Edit
                                        </div>';
                                }
                                if(in_array('create', $pagevals['permision'])){
                                    $create = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox" class="permision"  checked="checked"  name="create" value="create" id="inlineCheckbox1" style="opacity: 0;"></span></div> Create
                                        </div>';
                                }
                                if(in_array('remove', $pagevals['permision'])){
                                    $remove = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision" checked="checked" name="remove" value="remove" id="inlineCheckbox1" style="opacity: 0;"></span></div> Remove
                                        </div>';
                                }
                                 $permisions = $index.$view.$edit.$create.$remove;
                                echo $permisions;
                            }
                            
                            elseif($pagevals['module']== 'user'){
                                if(in_array('view', $pagevals['permision'])){
                                    $view = '<div class="left marginT5 marginR10">
                                        <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox" class="permision"  checked="checked" name="view" value="view" id="inlineCheckbox1" style="opacity: 0;"></span></div> View
                                    </div>';
                                }
                                if(in_array('index', $pagevals['permision'])){
                                    $index = '<div class="left marginT5 marginR10">
                                                <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision" checked="checked" name="index" value="index" id="inlineCheckbox1" style="opacity: 0;"></span></div> View all
                                            </div>';
                                }
                                if(in_array('edit', $pagevals['permision'])){
                                     $edit = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision" checked="checked" name="edit" value="edit" id="inlineCheckbox1" style="opacity: 0;"></span></div> Edit
                                        </div>';
                                }
                                if(in_array('create', $pagevals['permision'])){
                                    $create = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox" class="permision"  checked="checked"  name="create" value="create" id="inlineCheckbox1" style="opacity: 0;"></span></div> Create
                                        </div>';
                                }
                                if(in_array('waiting', $pagevals['permision'])){
                                    $waiting = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox" class="permision"  checked="checked" name="waiting" value="waiting" id="inlineCheckbox1" style="opacity: 0;"></span></div> Waiting
                                        </div>';
                                }
                                if(in_array('banned', $pagevals['permision'])){
                                    $banned = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision"  checked="checked" name="banned" value="banned" id="inlineCheckbox1" style="opacity: 0;"></span></div> Banned
                                        </div>';
                                }
                                if(in_array('active', $pagevals['permision'])){
                                    $active = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision" checked="checked" name="active" value="active" id="inlineCheckbox1" style="opacity: 0;"></span></div> Active
                                        </div>';
                                }
                                if(in_array('lock', $pagevals['permision'])){
                                    $lock = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox" class="permision"  checked="checked" name="lock" value="lock" id="inlineCheckbox1" style="opacity: 0;"></span></div> Lock
                                        </div>';
                                }
                                if(in_array('restore', $pagevals['permision'])){
                                    $restore = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision" checked="checked" name="restore" value="restore" id="inlineCheckbox1" style="opacity: 0;"></span></div> Restore
                                        </div>';
                                }
                                $permisions = $index.$view.$edit.$create.$waiting.$active.$banned.$lock.$restore;
                                echo $permisions;
                            }
                            
                            elseif($pagevals['module']== 'prcategory' || $pagevals['module']== 'pcategory'  || $pagevals['module']== 'ecategory'  || $pagevals['module'] == 'slidebanner'){
                                if(in_array('view', $pagevals['permision'])){
                                    $view = '<div class="left marginT5 marginR10">
                                        <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox" class="permision"  checked="checked" name="view" value="view" id="inlineCheckbox1" style="opacity: 0;"></span></div> View
                                    </div>';
                                }
                                if(in_array('index', $pagevals['permision'])){
                                    $index = '<div class="left marginT5 marginR10">
                                                <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision" checked="checked" name="index" value="index" id="inlineCheckbox1" style="opacity: 0;"></span></div> View all
                                            </div>';
                                }
                                if(in_array('edit', $pagevals['permision'])){
                                     $edit = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox" class="permision"  checked="checked" name="edit" value="edit" id="inlineCheckbox1" style="opacity: 0;"></span></div> Edit
                                        </div>';
                                }
                                if(in_array('create', $pagevals['permision'])){
                                    $create = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox" class="permision"  checked="checked"  name="create" value="create" id="inlineCheckbox1" style="opacity: 0;"></span></div> Create
                                        </div>';
                                }
                                
                                if(in_array('active', $pagevals['permision'])){
                                    $active = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox" class="permision"  checked="checked" name="active" value="active" id="inlineCheckbox1" style="opacity: 0;"></span></div> Active
                                        </div>';
                                }
                                if(in_array('block', $pagevals['permision'])){
                                    $block = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox" class="permision"  checked="checked" name="block" value="block" id="inlineCheckbox1" style="opacity: 0;"></span></div> Block
                                        </div>';
                                }
                                if(in_array('remove', $pagevals['permision'])){
                                    $remove = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision" checked="checked" name="remove" value="remove" id="inlineCheckbox1" style="opacity: 0;"></span></div> Remove
                                        </div>';
                                }
                               
                                $permisions = $index.$view.$edit.$create.$active.$block.$remove;
                                echo $permisions;
                            }
                            else{
                                //print_r($pagevals['permision']);
                                if(in_array('view', $pagevals['permision'])){
                                    $view = '<div class="left marginT5 marginR10">
                                        <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox" class="permision"  checked="checked" name="view" value="view" id="inlineCheckbox1" style="opacity: 0;"></span></div> View
                                    </div>';
                                }
                                if(in_array('index', $pagevals['permision'])){
                                    $index = '<div class="left marginT5 marginR10">
                                                <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision" checked="checked" name="index" value="index" id="inlineCheckbox1" style="opacity: 0;"></span></div> View all
                                            </div>';
                                }
                                if(in_array('edit', $pagevals['permision'])){
                                     $edit = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox" class="permision"  checked="checked" name="edit" value="edit" id="inlineCheckbox1" style="opacity: 0;"></span></div> Edit
                                        </div>';
                                }
                                if(in_array('create', $pagevals['permision'])){
                                    $create = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox" class="permision"  checked="checked"  name="create" value="create" id="inlineCheckbox1" style="opacity: 0;"></span></div> Create
                                        </div>';
                                }
                                if(in_array('pending', $pagevals['permision'])){
                                    $pending = ' <div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox" class="permision"  checked="checked" name="pending" value="pending" id="inlineCheckbox1" style="opacity: 0;"></span></div> Pending
                                        </div>';
                                }
                                if(in_array('approve', $pagevals['permision'])){
                                   $approve = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox" class="permision"  checked="checked" name="approve" value="approve" id="inlineCheckbox1" style="opacity: 0;"></span></div> Approve
                                        </div>';
                                }
                                if(in_array('active', $pagevals['permision'])){
                                    $active = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox" class="permision"  checked="checked" name="active" value="active" id="inlineCheckbox1" style="opacity: 0;"></span></div> Active
                                        </div>';
                                }
                                if(in_array('block', $pagevals['permision'])){
                                    $block = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox" class="permision"  checked="checked" name="block" value="block" id="inlineCheckbox1" style="opacity: 0;"></span></div> Block
                                        </div>';
                                }
                                if(in_array('remove', $pagevals['permision'])){
                                    $remove = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision" checked="checked" name="remove" value="remove" id="inlineCheckbox1" style="opacity: 0;"></span></div> Remove
                                        </div>';
                                }
                                if(in_array('restore', $pagevals['permision'])){
                                    $restore = '<div class="left marginT5 marginR10">
                                            <div class="checker" id="uniform-inlineCheckbox1"><span ><input type="checkbox"  class="permision" checked="checked" name="restore" value="restore" id="inlineCheckbox1" style="opacity: 0;"></span></div> Restore
                                        </div>';
                                }
                                $permisions = $index.$view.$edit.$create.$pending.$approve.$active.$block.$remove.$restore;
                                echo $permisions;
                            }
                        ?>
                       
                    </div>
                </div> 
            </div>
            
            <div class="form-row row-fluid">        
                    <div class="span12">
                        <div class="row-fluid">
                            <div class="form-actions">
                            <div class="span3"></div>
                            <div class="span4 controls">
                                <button type="submit" id="save" class="btn btn-info marginR10">Save</button>
                                <button class="btn btn-danger" id="cancel">Hủy</button>
                            </div>
                            </div>
                        </div>
                    </div>   
                </div>
            
        </form>

    </div>

</div>

     